/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.system.xml;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.kxml2.io.KXmlParser;

/**
 *
 * @author TOSHIBA
 */
public class XmlReaderWriter {
    public static String filePath = "file:///root1/";

    private XmlReaderWriter() {
    }

    public static XmlReaderWriter getInstance(){
        if(m_instance == null)
            m_instance = new XmlReaderWriter();

        return m_instance;
    }

    public XmlNode readFromXmlFile(String xmlFilePath) {
        XmlNode             retval  = null;
        InputStream         is      = getClass().getResourceAsStream(xmlFilePath);
        InputStreamReader   insr    = null;
        KXmlParser          parser  = new KXmlParser();

        try {
            insr = new InputStreamReader(is);
            parser.setInput(insr);
            GenericXmlParser gParser = new GenericXmlParser();
            retval = gParser.parseXML(parser, true);
        } catch (Exception ex) {
		} finally {
            try {
                insr.close();
                is.close();
            } catch (IOException ex) {}
        }

        return retval;
    }

    //Members
    private static XmlReaderWriter m_instance;
}
